package com.df.hitime.base;


import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.Optional;

/**
 *  其他service 需要基础该service
 * @author huangwl
 * @date 2018/11/20 9:56
 */

public abstract class BaseService<T extends BaseModel> implements PagingAndSortingRepository<T,Integer> {

    abstract protected BaseRepository<T> getBaseRepository();


    @Override
    public Iterable<T> findAll(Sort sort) {
        return getBaseRepository().findAll(sort);
    }

    @Override
    public Page<T> findAll(Pageable pageable) {
        return getBaseRepository().findAll(pageable);
    }

    @Override
    public <S extends T> S save(S s) {
        return getBaseRepository().save(s);
    }

    @Override
    public <S extends T> Iterable<S> saveAll(Iterable<S> iterable) {
        return getBaseRepository().saveAll(iterable);
    }

    @Override
    public Optional<T> findById(Integer integer) {
        return getBaseRepository().findById(integer);
    }

    @Override
    public boolean existsById(Integer integer) {
        return getBaseRepository().existsById(integer);
    }

    @Override
    public Iterable<T> findAll() {
        return getBaseRepository().findAll();
    }

    @Override
    public Iterable<T> findAllById(Iterable<Integer> iterable) {
        return getBaseRepository().findAllById(iterable);
    }

    @Override
    public long count() {
        return getBaseRepository().count();
    }

    @Override
    public void deleteById(Integer integer) {
        getBaseRepository().deleteById(integer);
    }

    @Override
    public void delete(T t) {
        getBaseRepository().delete(t);
    }

    @Override
    public void deleteAll(Iterable<? extends T> iterable) {
        getBaseRepository().deleteAll(iterable);
    }

    @Override
    public void deleteAll() {
        getBaseRepository().deleteAll();
    }
}
